//
//  ZhuanzhangViewController.m
//  specialine
//
//  Created by 往返网络 on 17/7/15.
//  Copyright © 2017年 com. All rights reserved.
//

#import "ZhuanzhangViewController.h"
#import "ZhuanSearchViewController.h" //转账搜索联系人vc
#import "ZhifuPass1ViewController.h" //发送验证码
#import "ConfigZhuangViewController.h" //转账确认
#import "PublicMethod.h"
#define return_tag 2000
#define next_tag 2001
#define cancel_tag 2002
#define forget_tag 2003
#define change_tag 2004
#define cancel1_tag 2005
#define yuebtn_tag 2006
#define bankbtn_tag 2007
#define kDotSize CGSizeMake (10, 10) //密码点的大小
#define kDotCount 6  //密码个数
#define K_Field_Height 110.0/H_BASE*SCREEN_H  //每一个输入框的高度
//定义查询银行卡URL
#define URL_CHECKBANK [NSString stringWithFormat:@"%@/Appcustomernewer/Pay/payTransfer?type=get",BASE_URL]
//定义转账下一步URL
#define URL_NEXTZHUAN [NSString stringWithFormat:@"%@/Appcustomernewer/Pay/payTransferToSecond?type=get",BASE_URL]
@interface ZhuanzhangViewController ()<UITextFieldDelegate>
@property (nonatomic,strong)AFHTTPSessionManager* manger;
@end
@implementation ZhuanzhangViewController{
    
    UIView * firstview;
    UIView * thirdview; //姓名，电话
    UILabel * namelab;
    UILabel * phonelab;
    UITextField * searchtf;
    UIView * secondview;
    UITextField *  zhuanzhangtf;
    UITextField * beizhutf;
    UIButton * nextbtn;
    UIView * zhifuview; //支付密码界面
    UIView * zhifustyleview; //支付方式界面
    UITextField * textFieldmima; //密码输入TF
    NSMutableArray * dotArray; //用于放密码黑点的数组
    UIView * mengbanview; //蒙板
       UILabel * changelab; //更改支付方式lab
    UIImageView * im; //支付方式银行logo
    UILabel * keyuelab; //可用余额
    UILabel * banklab;//支付银行lab
    UIButton * yuebtn;  //余额支付
    UIButton * bankbtn;  //银行支付
    UILabel * sureyue;   //余额支付对勾
    UILabel * surebank; //银行支付对勾
    
    NSString * namestr; //对方姓名
    NSString * phonestr; //对方电话
    NSString * user_typestr; //对方用户类型（货主 专线）
    NSString * pszhuangzhang; //转账密码
    NSString * zhifu_type; // 余额 或者银行卡支付
    NSDictionary * userinfo; //选择账户的信息
    NSString * card_type;  //01借记卡 02贷记卡
    NSString * bank_id; // 银行卡id
    NSString * sendphone; // 转账确认要显示的手机号，（用余额装帐，则显示当前手机号，银行转账泽显示本卡绑定手机号）
}

- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self checkBank];
    [self createUI];
    zhifu_type = @"1"; //默认余额支付
    // Do any additional setup after loading the view.
}

#pragma mark  --------- -- - - - - - - 查询当前银行卡－ － －－ － － － － － －
- (void)checkBank{
    
    //请求账号信息，余额等，赋值。。
    UIImageView * ima = [PublicMethod startAnimation];
    
    NSString * token = [[NSUserDefaults standardUserDefaults]objectForKey:USER_TOCKE];
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@",URL_CHECKBANK,token];
    
    NSLog(@"转账银行卡信息 url %@",url);
    [self.manger GET:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSInteger code = [dict[@"code"]integerValue];
            if (code == 0) {
                // 停止动画
                [ima stopAnimating];
                //获得银行卡号，余额，银行名称，logo ID值
                NSDictionary * info = dict[@"info"];
                keyuelab.text = info[@"balance"];
                banklab.text  = info[@"bank_name"];
                bank_id = info[@"bank_id"];
                card_type = info[@"card_type"];
                sendphone = info[@"telephone"];
                NSLog(@"银行卡 类型%@  银行卡绑定手机号%@,id %@",card_type,bank_id,sendphone);
                im.image = [UIImage imageNamed:bank_id];
                
            }else{
                
                [ima stopAnimating];
                ALERT(@"提示", dict[@"info"], self, @"确定", nil);
            }
            
        }
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        
        [ima stopAnimating];
        
    }];
}

- (void)nextZhuangzhang{
    
    //请求账号信息，余额等，赋值。。
    UIImageView * ima = [PublicMethod startAnimation];
    
    NSString * token = [[NSUserDefaults standardUserDefaults]objectForKey:USER_TOCKE];
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@&mobile=%@&userType=%@&money=%@&desc=%@&type=%@&password=%@",URL_NEXTZHUAN,token,phonestr,user_typestr,zhuanzhangtf.text,beizhutf.text,zhifu_type,pszhuangzhang];
    //中文转码
    NSString * URL  = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSLog(@"下一步转账 url %@",URL);
    [self.manger GET:URL parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSInteger code = [dict[@"code"]integerValue];
            if (code == 0) {
                // 停止动画
                [ima stopAnimating];
                ConfigZhuangViewController * configvc = [[ConfigZhuangViewController alloc]init];
                configvc.jinestring = zhuanzhangtf.text;
                configvc.phonestring = phonestr;
                configvc.user_name = namestr;
                configvc.user_type  = user_typestr;
//                NSDictionary * info = dict[@"info"];
                if ([zhifu_type isEqualToString:@"1"]) {
                    //使用余额转账
                    configvc.sendphone  = [[NSUserDefaults standardUserDefaults]objectForKey:USERDEFAULTS_PHONE];

                }else if ([zhifu_type isEqualToString:@"2"]){
                
                    configvc.sendphone = sendphone;
                }
                NSLog(@"确认转账的手机号 。。。%@", configvc.sendphone);
                configvc.userinfo = userinfo;
                configvc.zhifu_type = zhifu_type;
                [self.navigationController pushViewController:configvc animated:YES];

            }else{
                
                [ima stopAnimating];
                ALERT(@"提示", dict[@"info"], self, @"确定", nil);
                
            }
            
        }
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        
        [ima stopAnimating];
        
    }];
}



- (void)createUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    float fontsize = 17;
    
    fontsize = SCREEN_H < 667 ? 15 : 19;
    
    if (SCREEN_H == 667) {
        
        fontsize = 17;
    }
    self.view.backgroundColor = COLORRGBA(239, 239, 239, 1);
    //设置表头
    UIView * titleview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 128.0/1334*SCREEN_H)];
    
    titleview.backgroundColor = COLORRGBA(7, 24, 57, 1);
    
    [self.view addSubview:titleview];
    
    //title
    UILabel * titlelab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20.0, SCREEN_W, 90.0/H_BASE*SCREEN_H)];
    titlelab.text = @"转账";
    titlelab.textColor = [UIColor whiteColor];
    [self.view addSubview:titlelab];
    titlelab.textAlignment = NSTextAlignmentCenter;
    titlelab.font = [UIFont systemFontOfSize:fontsize];
    
    UILabel * leftlable  = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+14.0/1334*SCREEN_H, 150.0/W_BASE*SCREEN_W, 60.0/1334.0*SCREEN_H)];
    leftlable.textAlignment = NSTextAlignmentCenter;
    NSString * endstr = @"\U0000e697";
    NSString * text = [NSString stringWithFormat:@"%@%@",endstr,@"返回"];
    leftlable.attributedText = [self changeLabelWithText2:text andStartplace:endstr andendplae:nil andfontsize:fontsize-2];
    leftlable.textColor = [UIColor whiteColor];
    [self.view addSubview:leftlable];
    
    UIButton * returnbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 150.0/W_BASE*SCREEN_W, 150.0/H_BASE*SCREEN_H)];
    [returnbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    returnbtn.tag = return_tag;
    [self.view addSubview:returnbtn];
    
    firstview = [[UIView alloc]initWithFrame:CGRectMake(0, 127.0/H_BASE*SCREEN_H, SCREEN_W, 90.0/H_BASE*SCREEN_H)];
    firstview.backgroundColor = COLORRGBA(239, 239, 239, 1);
    [self.view addSubview:firstview];
    searchtf = [[UITextField alloc]initWithFrame:CGRectMake(23.0/W_BASE*SCREEN_W, 15.0/H_BASE*SCREEN_H, SCREEN_W - 46.0/W_BASE*SCREEN_W, 60.0/H_BASE*SCREEN_H)];
    searchtf.backgroundColor = [UIColor whiteColor];
    searchtf.layer.cornerRadius = fontsize-4;
    searchtf.clipsToBounds = YES;
//    searchtf.delegate = self;
    searchtf.placeholder = @"搜索用户手机号";
    searchtf.font = [UIFont systemFontOfSize:fontsize-3];
    [firstview addSubview:searchtf];
    
    UIButton * searbtn = [[UIButton alloc]initWithFrame:searchtf.frame];
    [searbtn addTarget:self action:@selector(searchDisplay) forControlEvents:UIControlEventTouchUpInside];
    [firstview addSubview:searbtn];
    
    UILabel * leftlab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,65.0/W_BASE*SCREEN_W , 60.0/H_BASE*SCREEN_H)];
    leftlab.text = @"\U0000e6ac";
    leftlab.textAlignment = NSTextAlignmentRight;
    leftlab.textColor = COLORRGBA(153, 153, 153, 1);
    leftlab.font = [UIFont fontWithName:@"iconfont" size:fontsize-3];
    searchtf.leftView = leftlab;
    searchtf.leftViewMode = UITextFieldViewModeAlways;
    
    thirdview = [[UIView alloc]initWithFrame:CGRectZero];
    thirdview.backgroundColor = [UIColor whiteColor];
    namelab = [[UILabel alloc]initWithFrame:CGRectMake(25.0/W_BASE*SCREEN_W, 0, 154.0/W_BASE*SCREEN_W, 80.0/H_BASE*SCREEN_H)];
    namelab.font = [UIFont systemFontOfSize:fontsize-3];
    namelab.textAlignment = NSTextAlignmentLeft;
    namelab.textColor = [UIColor blackColor];
    [thirdview addSubview:namelab];
    phonelab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_W-25.0/W_BASE*SCREEN_W-200.0/W_BASE*SCREEN_W, 0, 200.0/W_BASE*SCREEN_W, 80.0/H_BASE*SCREEN_H)];
    phonelab.textAlignment = NSTextAlignmentRight;
    phonelab.font = [UIFont systemFontOfSize:fontsize-3];
    phonelab.textColor = [UIColor blackColor];
    [thirdview addSubview:phonelab];
    [firstview addSubview:thirdview];

    secondview = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(firstview.frame), SCREEN_W, SCREEN_H - CGRectGetMaxY(firstview.frame))];
    secondview.backgroundColor = COLORRGBA(239, 239, 239, 1);
    [self.view addSubview:secondview];
    UIView * jineview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 200.0/H_BASE*SCREEN_H)];
    jineview.backgroundColor = [UIColor whiteColor];
    [secondview addSubview:jineview];
    UILabel *  zhuanlab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(searchtf.frame), 0, 200.0/W_BASE*SCREEN_W, 66.0/H_BASE*SCREEN_H)];
    zhuanlab.text = @"转账金额";
    zhuanlab.font = [UIFont systemFontOfSize:fontsize-3];
    [secondview addSubview:zhuanlab];
    zhuanlab.textColor = [UIColor blackColor];
    UILabel * logo = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(zhuanlab.frame), CGRectGetMaxY(zhuanlab.frame), 36.0/W_BASE*SCREEN_W, 56.0/H_BASE*SCREEN_H)];
    logo.textColor = [UIColor blackColor];
    logo.text = @"￥";
    logo.font = [UIFont systemFontOfSize:fontsize+8];
    [jineview addSubview:logo];
     zhuanzhangtf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(logo.frame)+8.0/W_BASE*SCREEN_W, CGRectGetMaxY(zhuanlab.frame), 300.0/W_BASE*SCREEN_W, 56.0/H_BASE*SCREEN_H)];
    zhuanzhangtf.userInteractionEnabled = NO; //不可用,等有名字时，才可以
    zhuanzhangtf.textColor = [UIColor blackColor];
    [secondview addSubview:zhuanzhangtf];
    zhuanzhangtf.font = [UIFont systemFontOfSize:fontsize+8];
    //    chongzhitf.placeholder = @"请输入充值金额";
    zhuanzhangtf.keyboardType = UIKeyboardTypeDecimalPad;
    zhuanzhangtf.delegate = self;
    UIView * breakview = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(logo.frame), CGRectGetMaxY(zhuanzhangtf.frame)+19.0/H_BASE*SCREEN_H, SCREEN_W - CGRectGetMinX(logo.frame) , 1)];
    breakview.backgroundColor = COLORRGBA(239, 239, 239, 1);
    [secondview addSubview:breakview];
    UILabel * beizhulab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(logo.frame), CGRectGetMaxY(breakview.frame), 120.0/W_BASE*SCREEN_W, 59.0/H_BASE*SCREEN_H)];
    beizhulab.textColor = [UIColor blackColor];
    [secondview addSubview:beizhulab];
    beizhulab.text = @"添加备注";
    beizhulab.font = [UIFont systemFontOfSize:fontsize-4];
    beizhutf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(beizhulab.frame), CGRectGetMinY(beizhulab.frame), SCREEN_W - CGRectGetMaxX(beizhulab.frame), CGRectGetHeight(beizhulab.frame))];
    beizhutf.textColor = [UIColor blackColor];
    beizhutf.font = [UIFont systemFontOfSize:fontsize-4];
    [secondview addSubview:beizhutf];
    beizhutf.delegate = self;
    beizhutf.userInteractionEnabled = NO;
    beizhutf.keyboardType = UIKeyboardTypeDefault;
    
    nextbtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMinX(beizhulab.frame), CGRectGetMaxY(beizhutf.frame)+62.0/H_BASE*SCREEN_H, SCREEN_W-CGRectGetMinX(beizhulab.frame)*2, 80.0/H_BASE*SCREEN_H)];
    nextbtn.backgroundColor = COLORRGBA(227, 227, 227, 1);
    nextbtn.layer.cornerRadius = 2;
    nextbtn.clipsToBounds = YES;
    [secondview addSubview:nextbtn];
    nextbtn.titleLabel.font = [UIFont systemFontOfSize:fontsize-2];
    [nextbtn setTitle:@"下一步" forState:UIControlStateNormal];
    [nextbtn setTitleColor:COLORRGBA(204, 204, 204, 1) forState:UIControlStateNormal];
    nextbtn.tag = next_tag;
    [nextbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    nextbtn.userInteractionEnabled  = NO;
 
    changelab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(nextbtn.frame), SCREEN_W, 65.0/H_BASE*SCREEN_H)];
    NSString * text1 = @"使用余额支付，";
    NSString * endstr1 = [NSString stringWithFormat:@"%@",@"更换"];
    changelab.text = @"使用余额支付，更换";
    changelab.attributedText = [self changeLabelWithText:changelab.text andStartplace:text1 andendplae:endstr1 andfontsize:fontsize-2];
    [secondview addSubview:changelab];
    changelab.textAlignment = NSTextAlignmentCenter;
    UIButton * changebtn = [[UIButton alloc]initWithFrame:CGRectMake(400.0/W_BASE*SCREEN_W, CGRectGetMaxY(nextbtn.frame), SCREEN_W-400.0/W_BASE*SCREEN_W, 65.0/H_BASE*SCREEN_H)];
    [changebtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    [secondview addSubview:changebtn];
    changebtn.tag = change_tag;
    
    //支付输入密码
    mengbanview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 397.0/H_BASE*SCREEN_H)];
    mengbanview.backgroundColor = COLORRGBA(153, 153, 153, 0.4);
    
    zhifuview = [[UIView alloc]initWithFrame:CGRectMake(0, 397.0/H_BASE*SCREEN_H, SCREEN_W, SCREEN_H-397.0/H_BASE*SCREEN_H)];
    zhifuview.backgroundColor = [UIColor whiteColor];
    //    [self.view addSubview:zhifuview];
    UIButton * cancelbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 112.0/W_BASE*SCREEN_W, 112.0/W_BASE*SCREEN_W)];
    //    cancelbtn.backgroundColor = [UIColor yellowColor];
    [zhifuview addSubview:cancelbtn];
    [cancelbtn setTitle:@"\U0000e69a" forState:UIControlStateNormal];
    cancelbtn.titleLabel.font = [UIFont fontWithName:@"iconfont" size:fontsize];
    cancelbtn.tag = cancel_tag;
    [cancelbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    [cancelbtn setTitleColor:COLORRGBA(159, 159, 159, 1) forState:UIControlStateNormal];
    UILabel * zhifulab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 112.0/W_BASE*SCREEN_W)];
    zhifulab.text = @"请输入支付密码";
    [zhifuview addSubview:zhifulab];
    zhifulab.font = [UIFont systemFontOfSize:fontsize +1];
    zhifulab.textColor = [UIColor blackColor];
    zhifulab.textAlignment = NSTextAlignmentCenter;
    UIView * breakview1 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(zhifulab.frame), SCREEN_W, 0.5)];
    breakview1.backgroundColor = COLORRGBA(204, 204, 204, 1);
    [zhifuview addSubview:breakview1];
    //    zhifuview.hidden = YES;
    textFieldmima = [[UITextField alloc] initWithFrame:CGRectMake(30.0/W_BASE*SCREEN_W, CGRectGetMaxY(breakview.frame)+46.0/H_BASE*SCREEN_H, SCREEN_W - 60.0/W_BASE*SCREEN_W, K_Field_Height)];
    textFieldmima.backgroundColor = [UIColor whiteColor];
    //输入的文字颜色为白色
    textFieldmima.textColor = [UIColor whiteColor];
    //输入框光标的颜色为白色
    textFieldmima.tintColor = [UIColor whiteColor];
    textFieldmima.delegate = self;
    textFieldmima.autocapitalizationType = UITextAutocapitalizationTypeNone;
    textFieldmima.keyboardType = UIKeyboardTypeNumberPad;
    textFieldmima.layer.borderColor = [COLORRGBA(204, 204, 204, 1)CGColor];
    textFieldmima.layer.borderWidth = 1;
    [textFieldmima addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [zhifuview addSubview:textFieldmima];
    [self initPwdTextField];//创建密码tf的分割线
    
    UIButton * forgetbtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_W - 137.0/W_BASE*SCREEN_W-26.0/W_BASE*SCREEN_W, CGRectGetMaxY(textFieldmima.frame), 137.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    //    forgetbtn.backgroundColor = [UIColor purpleColor];
    forgetbtn.titleLabel.textAlignment = NSTextAlignmentRight;
    forgetbtn.titleLabel.font = [UIFont systemFontOfSize:fontsize-3];
    [forgetbtn setTitle:@"忘记密码?" forState:UIControlStateNormal];
    [forgetbtn setTitleColor:COLORRGBA(47, 165, 255, 1) forState:UIControlStateNormal];
    [zhifuview addSubview:forgetbtn];
    forgetbtn.tag = forget_tag;
    [forgetbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //支付方式界面
    zhifustyleview = [[UIView alloc]initWithFrame:CGRectMake(0, 397.0/H_BASE*SCREEN_H, SCREEN_W, SCREEN_H-397.0/H_BASE*SCREEN_H)];
    zhifustyleview.backgroundColor = [UIColor whiteColor];
    //    [self.view addSubview:zhifuview];
    UIButton * cancelbtn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 112.0/W_BASE*SCREEN_W, 112.0/W_BASE*SCREEN_W)];
    [zhifustyleview addSubview:cancelbtn1];
    [cancelbtn1 setTitle:@"\U0000e69a" forState:UIControlStateNormal];
    cancelbtn1.titleLabel.font = [UIFont fontWithName:@"iconfont" size:fontsize];
    cancelbtn1.tag = cancel1_tag;
    [cancelbtn1 addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    [cancelbtn1 setTitleColor:COLORRGBA(159, 159, 159, 1) forState:UIControlStateNormal];
    UILabel * zhifulab1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 112.0/W_BASE*SCREEN_W)];
    zhifulab1.text = @"选择支付方式";
    [zhifustyleview addSubview:zhifulab1];
    zhifulab1.font = [UIFont systemFontOfSize:fontsize +1];
    zhifulab1.textColor = [UIColor blackColor];
    zhifulab1.textAlignment = NSTextAlignmentCenter;
    UIView * breakview2 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(zhifulab.frame), SCREEN_W, 0.5)];
    breakview2.backgroundColor = COLORRGBA(204, 204, 204, 1);
    [zhifustyleview addSubview:breakview2];
    
    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(breakview2.frame), SCREEN_W, 110.0/H_BASE*SCREEN_H)];
    [zhifustyleview addSubview:view1];
    UILabel * iconlab = [[UILabel alloc]initWithFrame:CGRectMake(20.0/W_BASE*SCREEN_W, 20.0/H_BASE*SCREEN_H, 60.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    iconlab.text = @"¥";
    iconlab.textAlignment = NSTextAlignmentCenter;
    iconlab.textColor = COLORRGBA(47, 165, 255, 1);
    [view1 addSubview:iconlab];
    iconlab.font = [UIFont systemFontOfSize:fontsize+8];
    
    UILabel * yuetitle = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxY(iconlab.frame)+20.0/W_BASE*SCREEN_W, CGRectGetMinY(breakview2.frame)+20.0/H_BASE*SCREEN_H, 300.0/W_BASE*SCREEN_W, 45.0/H_BASE*SCREEN_W)];
    yuetitle.text = @"账户余额";
    yuetitle.textColor = [UIColor blackColor];
    yuetitle.font = [UIFont boldSystemFontOfSize:fontsize-2];
    [zhifustyleview addSubview:yuetitle];
    yuetitle.textAlignment = NSTextAlignmentLeft;
    
    keyuelab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(yuetitle.frame), CGRectGetMaxY(yuetitle.frame)+3.0/H_BASE*SCREEN_H, 300.0/W_BASE*SCREEN_W, 45.0/H_BASE*SCREEN_H)];
    keyuelab.textAlignment = NSTextAlignmentLeft;
    keyuelab.font = [UIFont systemFontOfSize:fontsize-4];
    keyuelab.textColor = COLORRGBA(153, 153, 153, 1);
    [zhifustyleview addSubview:keyuelab];
    keyuelab.text = @"可用余额1000.00元";
    
    sureyue = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_W - 80.0/W_BASE*SCREEN_W, 20.0/H_BASE*SCREEN_H+CGRectGetMaxY(breakview2.frame), 60.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    sureyue.text = @"\U0000e6ad";
    sureyue.font = [UIFont fontWithName:@"iconfont" size:fontsize+13];
    sureyue.textColor = COLORRGBA(47, 165, 255, 1);
    [zhifustyleview addSubview:sureyue];
    
    UIView * breakview3 = [[UIView alloc]initWithFrame:CGRectMake(20.0/W_BASE*SCREEN_W, CGRectGetMaxY(breakview2.frame)+110.0/H_BASE*SCREEN_H, SCREEN_W-20.0/W_BASE*SCREEN_W, 0.5)];
    breakview3.backgroundColor = COLORRGBA(204, 204, 204, 1);
    [zhifustyleview addSubview:breakview3];
    
    UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(breakview3.frame), SCREEN_W, 110.0/H_BASE*SCREEN_H)];
    [zhifustyleview addSubview:view2];
    im = [[UIImageView alloc]initWithFrame:CGRectMake(20.0/W_BASE*SCREEN_W, 20.0/H_BASE*SCREEN_H, 70.0/W_BASE*SCREEN_W, 70.0/W_BASE*SCREEN_W)];
    im.backgroundColor = [UIColor whiteColor];
    [view2 addSubview:im];
    
    UILabel * banktitle = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxY(im.frame)+20.0/W_BASE*SCREEN_W, CGRectGetMaxY(breakview3.frame)+20.0/H_BASE*SCREEN_H, 300.0/W_BASE*SCREEN_W, 45.0/H_BASE*SCREEN_W)];
    banktitle.text = @"中国农业银行储蓄卡";
    banktitle.textColor = [UIColor blackColor];
    banktitle.font = [UIFont boldSystemFontOfSize:fontsize-2];
    [zhifustyleview addSubview:banktitle];
    banktitle.textAlignment = NSTextAlignmentLeft;
    
    banklab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(yuetitle.frame), CGRectGetMaxY(banktitle.frame)+3.0/H_BASE*SCREEN_H, 300.0/W_BASE*SCREEN_W, 45.0/H_BASE*SCREEN_H)];
    banklab.textAlignment = NSTextAlignmentLeft;
    banklab.font = [UIFont systemFontOfSize:fontsize-4];
    banklab.textColor = COLORRGBA(153, 153, 153, 1);
    [zhifustyleview addSubview:banklab];
    banklab.text = @"银行单笔限额10000.00元";

    surebank = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_W - 80.0/W_BASE*SCREEN_W, 20.0/H_BASE*SCREEN_H+CGRectGetMaxY(breakview3.frame), 60.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    surebank.text = @"\U0000e6ad";
    surebank.font = [UIFont fontWithName:@"iconfont" size:fontsize+13];
    surebank.textColor = COLORRGBA(47, 165, 255, 1);
    surebank.hidden = YES;
    [zhifustyleview addSubview:surebank];

    UIView * breakview4 = [[UIView alloc]initWithFrame:CGRectMake(20.0/W_BASE*SCREEN_W, CGRectGetMaxY(breakview3.frame)+110.0/H_BASE*SCREEN_H, SCREEN_W-20.0/W_BASE*SCREEN_W, 0.5)];
    breakview4.backgroundColor = COLORRGBA(204, 204, 204, 1);
    [zhifustyleview addSubview:breakview4];

    yuebtn = [[UIButton alloc]initWithFrame:view1.frame];
    [yuebtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    [zhifustyleview addSubview:yuebtn];
    yuebtn.tag = yuebtn_tag;
    
    bankbtn = [[UIButton alloc]initWithFrame:view2.frame];
    [bankbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    [zhifustyleview addSubview:bankbtn];
    bankbtn.tag = bankbtn_tag;
    
    
}
#pragma mark  -  -  起始地＋发货人名（终止地＋收货人名）格式化 － － －-- - -  -

-(NSMutableAttributedString*)changeLabelWithText2:(NSString*)needText andStartplace:(NSString *)startplace andendplae:(NSString *)endplace andfontsize:(float)fontsize
{
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:needText];
    NSInteger startlength = startplace.length;
    //起始格式化
    [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"iconfont" size:fontsize+2] range:NSMakeRange(0,startlength)];
    //    //尾部格式化
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:fontsize] range:NSMakeRange(startlength , needText.length  - startlength)];
    return attrString;
}

-(NSMutableAttributedString*)changeLabelWithText:(NSString*)needText andStartplace:(NSString *)startplace andendplae:(NSString *)endplace andfontsize:(float)fontsize
{
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:needText];
    NSInteger startlength = startplace.length;
    //起始格式化
    [attrString addAttribute:NSForegroundColorAttributeName value:COLORRGBA(102, 102, 102, 1) range:NSMakeRange(0,startlength)];
    //    //尾部格式化
    [attrString addAttribute:NSForegroundColorAttributeName value:COLORRGBA(56, 119, 246, 1) range:NSMakeRange(startlength , needText.length  - startlength)];
    return attrString;
}

#pragma mark  - - -- - - - - - 将输入密码的tf分割成点 － － － － － － － － － － －
- (void)initPwdTextField
{
    //每个密码输入框的宽度
    CGFloat width = (SCREEN_W - 32) / kDotCount;
    //生成分割线
    for (int i = 0; i < kDotCount - 1; i++) {
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFieldmima.frame) + (i + 1) * width, CGRectGetMinY(textFieldmima.frame), 1, K_Field_Height)];
        lineView.backgroundColor = COLORRGBA(204, 204, 204, 1);
        [zhifuview addSubview:lineView];
    }
    dotArray = [[NSMutableArray alloc] init];
    //生成中间的点
    for (int i = 0; i < kDotCount; i++) {
        UIView *dotView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFieldmima.frame) + (width - kDotCount) / 2 + i * width, CGRectGetMinY(textFieldmima.frame) + (K_Field_Height - kDotSize.height) / 2, kDotSize.width, kDotSize.height)];
        dotView.backgroundColor = [UIColor blackColor];
        dotView.layer.cornerRadius = kDotSize.width / 2.0f;
        dotView.clipsToBounds = YES;
        dotView.hidden = YES; //先隐藏
        [zhifuview addSubview:dotView];
        //把创建的黑色点加入到数组中
        [dotArray addObject:dotView];
    }
}

#pragma mark - - - - - - - - - - -  Action - - - - - - - - - - - - -

- (void)searchDisplay{
    
    ZhuanSearchViewController * searchvc = [[ZhuanSearchViewController alloc]init];
    searchvc.backBlock = ^(NSString * namestring,NSString * phonestring,NSString * user_type,NSDictionary * info){
        namestr = namestring;
        phonestr = phonestring;
        user_typestr = user_type;
        userinfo = info;
        [UIView animateWithDuration:0.5 animations:^{
            CGRect rect = CGRectMake(0, 127.0/H_BASE*SCREEN_H, SCREEN_W, 186.0/H_BASE*SCREEN_H);
            firstview.frame = rect;
            CGRect  rect1 = CGRectMake(0, 90.0/W_BASE*SCREEN_W, SCREEN_W, 80.0/H_BASE*SCREEN_H);
            thirdview.frame = rect1;
            if ([user_type isEqualToString:@"1"]) {
                namelab.text = [NSString stringWithFormat:@"%@(货主)",namestring];
            }else if ([user_type isEqualToString:@"2"]){
                namelab.text = [NSString stringWithFormat:@"%@(专线)",namestring];
            }
            phonelab.text = phonestring;
            CGRect rect2 = CGRectMake(0, CGRectGetMaxY(firstview.frame), SCREEN_W, SCREEN_H - CGRectGetMaxY(firstview.frame));
            secondview.frame = rect2;
            zhuanzhangtf.userInteractionEnabled = YES; //不可用,等有名字时，才可以
            beizhutf.userInteractionEnabled = YES;

        }];
        
    };
    [self.navigationController pushViewController:searchvc animated:YES];
}

- (void)enterClick:(UIButton *)btn{
    float fontsize = 17;
    
    fontsize = SCREEN_H < 667 ? 15 : 19;
    
    if (SCREEN_H == 667) {
        
        fontsize = 17;
    }

    switch (btn.tag) {
        case return_tag:
            //返回
            [self.navigationController popViewControllerAnimated:YES];
            break;
        case next_tag:
            //下一步
        {
            float zhuanzhangnum  = [zhuanzhangtf.text floatValue];
            if (zhuanzhangnum > 10000.00 ) {
                ALERT(@"提示", @"转账金额不超过10000元", self, @"确定", nil);
                return;
            }

            //显示键盘
            [UIView animateWithDuration:0.5 animations:^{
                [zhuanzhangtf resignFirstResponder];
                [self.view addSubview:mengbanview];
                [self.view addSubview:zhifuview];
                [textFieldmima becomeFirstResponder];
                textFieldmima.keyboardType = UIKeyboardTypeNumberPad;
                [self  initPwdTextField]; //
            }];
            break;
        }
        case cancel_tag:
        {
            //隐藏支付view
            [mengbanview removeFromSuperview];
            [zhifuview removeFromSuperview];
            [self.view endEditing:YES];
            [self  clearUpPassword];
        }
            case forget_tag:
        {
            [mengbanview removeFromSuperview];
            [zhifuview removeFromSuperview];
            [self.view endEditing:YES];
            [self  clearUpPassword];//清除密码
            ZhifuPass1ViewController * zhifuvc = [[ZhifuPass1ViewController alloc]init];
            [self.navigationController pushViewController:zhifuvc animated:YES];
        }
        case change_tag:
            //选择支付方式
        {
            NSLog(@"更换");
            [UIView animateWithDuration:0.5 animations:^{
                [self.view addSubview:mengbanview];
                [self.view addSubview:zhifustyleview];
                [self.view endEditing:YES];
            }];
            break;
        }
        case cancel1_tag:
        {
        //取消更换支付方式
            [mengbanview removeFromSuperview];
            [zhifustyleview removeFromSuperview];
            [self.view endEditing:YES];
        }
        case yuebtn_tag:
            //余额支付
        {
        //隐藏萌版，支付方式界面,传递支付方式
            sureyue.hidden = NO;
            surebank.hidden = YES;
            [mengbanview removeFromSuperview];
            [zhifustyleview removeFromSuperview];
            changelab.text = @"使用余额支付，更换";
            NSString * text1 = @"使用余额支付，";
            NSString * endstr1 = [NSString stringWithFormat:@"%@",@"更换"];
            changelab.attributedText = [self changeLabelWithText:changelab.text andStartplace:text1 andendplae:endstr1 andfontsize:fontsize-2];

            zhifu_type = @"1";
        }
            break;
        case bankbtn_tag:
            //银行支付
        {
            surebank.hidden = NO;
            sureyue.hidden = YES;
            [mengbanview removeFromSuperview];
            [zhifustyleview removeFromSuperview];
            NSString * text1 = @"使用银行卡支付，";
            NSString * endstr1 = [NSString stringWithFormat:@"%@",@"更换"];
            changelab.text = @"使用银行卡支付，更换";
            changelab.attributedText = [self changeLabelWithText:changelab.text andStartplace:text1 andendplae:endstr1 andfontsize:fontsize-2];
            zhifu_type = @"2";
        }
            break;
        default:
            break;
    }
}
/**
 *  重置显示的点
 */
- (void)textFieldDidChange:(UITextField *)textField
{
    NSLog(@"%@", textField.text);
    if (textField == textFieldmima) {
        for (UIView *dotView in dotArray) {
            dotView.hidden = YES;
        }
        for (int i = 0; i < textField.text.length; i++) {
            ((UIView *)[dotArray objectAtIndex:i]).hidden = NO;
        }
        if (textField.text.length == kDotCount) {
            NSLog(@"输入完毕");
        }
    }
}

#pragma mark - - - - - - - - - - Textfield Delegate  - -- - - - - - - -- - - - - -
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
        return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    //输入1位，下一步按钮变色
    NSString * textstring = [textField.text stringByReplacingCharactersInRange:range withString:string];
    pszhuangzhang = textstring;
       if (textField == zhuanzhangtf) {
        if (textstring.length >= 1) {
            nextbtn.backgroundColor = COLORRGBA(59, 214, 117, 1);
            nextbtn.userInteractionEnabled = YES;
            [nextbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            //            zhifuview.hidden = NO;
        }
    }
    else if (textField == textFieldmima){ //输入密码
        if([string isEqualToString:@"\n"]) {
            //按回车关闭键盘
            [textField resignFirstResponder];
            return NO;
        } else if(string.length == 0) {
            //判断是不是删除键
            return YES;
        }
        else if(textstring.length >= kDotCount) {
            //输入的字符个数大于6，则无法继续输入，返回NO表示禁止输入
            NSLog(@"输入的字符个数大于6，忽略输入");
            //判断密码是否正确，正确则提示校验成功
            //            [textFieldmima resignFirstResponder];
//            ALERT(@"提示", @"校验成功", self, @"确定", nil);
            //如果校验成功
            [zhifuview removeFromSuperview];
            [mengbanview removeFromSuperview];
            for (int i = 0; i < textField.text.length; i++) {
                ((UIView *)[dotArray objectAtIndex:i]).hidden = YES;
            }
                       [self nextZhuangzhang];
            [self clearUpPassword];// 清除密码

            return NO;
            
        } else {
            return YES;
        }
    }
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    return YES;
}
/**
 *  清除密码
 */

- (void)clearUpPassword
{
    textFieldmima.text = @"";
    [self textFieldDidChange:textFieldmima];
}

#pragma mark - - -- - - - 懒加载 ---- - -- - -

- (AFHTTPSessionManager*)manger{
    
    if (!_manger) {
        
        _manger = [AFHTTPSessionManager manager];
        
        _manger.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        _manger.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];
    }
    return _manger;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
